package ryulib;

import java.util.LinkedList;
import java.util.Queue;

import android.util.Log;

public class SuspensionQueue<T> {
	
	private Queue<T> _Buffer = new LinkedList<T>();
	
	public synchronized void clear() {
		_Buffer.clear();
		notifyAll();
	}
	
	public synchronized void offer(T t) {
		_Buffer.offer(t);
		notifyAll();
	}
	
	public synchronized T poll() {
		while (null == _Buffer.peek()) {
			try {
				wait();
			} catch (Exception e) {
		      	Log.e("RyuLib", "SuspensionQueue.poll() - " + e.getMessage());				
			}
		}
		
		return _Buffer.poll();
	}
	
	public synchronized boolean isEmpty() {
		return _Buffer.isEmpty();
	}
	
	public synchronized int size() {
		return _Buffer.size();
	}

}
